<template>
  <div class="unauthorized">
    <div class="content">
      <el-result
        icon="error"
        title="401"
        sub-title="抱歉，您没有权限访问此页面"
      >
        <template #extra>
          <el-button type="primary" @click="goToLogin">去登录</el-button>
          <el-button @click="goToDashboard">返回首页</el-button>
        </template>
      </el-result>
    </div>
  </div>
</template>

<script setup>
import { useRouter } from 'vue-router'

const router = useRouter()

const goToLogin = () => {
  // 清除可能过期的凭证
  localStorage.removeItem('user')
  localStorage.removeItem('token')
  router.push('/login')
}

const goToDashboard = () => {
  router.push('/dashboard')
}
</script>

<style scoped>
.unauthorized {
  height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  background-color: #f5f7fa;
}

.content {
  padding: 40px;
  background-color: #fff;
  border-radius: 8px;
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
}
</style> 